from utils.base import BaseSerializer
from apps.envs.models import (
    Env,
    EnvGlobalParams,
    Service,
    Plant,
    EnvPlant,
    EnvDb,
    EnvService,
    Module,
    Page,
    Headers,
)

from rest_framework import serializers


class EnvSerializers(BaseSerializer):

    class Meta:
        model = Env
        fields = '__all__'


class EnvGlobalParamsSerializers(BaseSerializer):
    env_name = serializers.CharField(source='env.name', read_only=True)

    class Meta:
        model = EnvGlobalParams
        fields = '__all__'


class ServiceSerializers(BaseSerializer):

    class Meta:
        model = Service
        fields = '__all__'


class HeadersSerializers(BaseSerializer):

    class Meta:
        model = Headers
        fields = '__all__'


class EnvServiceSerializers(BaseSerializer):
    env_name = serializers.CharField(source='env.name', read_only=True)
    service_name = serializers.CharField(source='service.name', read_only=True)

    class Meta:
        model = EnvService
        fields = ['env_name', 'service_name', 'id', 'create_time', 'update_time', 'create_by_name', 'update_by_name',
                  'env', 'service', 'host']


class PlantSerializers(BaseSerializer):

    class Meta:
        model = Plant
        fields = '__all__'


class EnvPlantSerializers(BaseSerializer):
    env_name = serializers.CharField(source='env.name', read_only=True)
    plant_name = serializers.CharField(source='plant.name', read_only=True)

    class Meta:
        model = EnvPlant
        fields = ['env_name', 'plant_name', 'id', 'create_time', 'update_time', 'create_by_name', 'update_by_name',
                  'env', 'plant', 'host']


class ModuleSerializers(BaseSerializer):

    plant_name = serializers.CharField(source='plant.name', read_only=True)

    class Meta:
        model = Module
        fields = '__all__'


class PageSerializers(BaseSerializer):

    module_name = serializers.CharField(source='module.name', read_only=True)
    plant_name = serializers.CharField(source='module.plant.name', read_only=True)

    class Meta:
        model = Page
        fields = '__all__'
